package com.queclink.ycm.common.utils;

import org.apache.commons.lang3.StringUtils;

/**
 * @author jim.li
 * @email jim.li@queclink.com
 * @date 2024-06-28 14:43:00
 */
public class StringUtil {

    public static String padZeroesToTheLeft(String original, int length) {
        if (StringUtils.isEmpty(original)) {
            original = "0";
        }
        // 计算需要补零的数量
        int numOfZeroesToPrepend = length - original.length();
        // 如果原始字符串长度已经等于或超过目标长度，则直接返回原始字符串
        if (numOfZeroesToPrepend <= 0) {
            return original;
        }
        // 使用StringBuilder来高效地拼接字符串
        StringBuilder sb = new StringBuilder(length);
        for (int i = 0; i < numOfZeroesToPrepend; i++) {
            sb.append('0');
        }
        sb.append(original);
        return sb.toString();
    }

    public static String replaceRav(String originalString) {
        // 替换字符
        String replacedString = originalString
                .replace("R", "")  // 替换 "R"
                .replace("A", "")  // 替换 "A"
                .replace("V", "")  // 替换 "V"
                .replace(".", "");  // 替换小数点

        return replacedString;
    }
}
